package de.jabc.sib.bio.ebi;

import de.jabc.adapter.bio.ebi.Branches;
import de.jabc.adapter.bio.ebi.LightweightServiceAdapter;
import de.jabc.adapter.bio.ebi.ServiceAdapter;
import de.metaframe.jabc.framework.execution.ExecutionEnvironment;
import de.metaframe.jabc.framework.sib.annotation.SIBClass;
import de.metaframe.jabc.framework.sib.annotation.SIBStatus;
import de.metaframe.jabc.framework.sib.parameter.ContextExpression;
import de.metaframe.jabc.framework.sib.parameter.ContextKey;
import de.metaframe.jabc.sib.ServiceAdapterDescriptor;

/**
 * Calls the EBI's EMBOSS Pepwindow - draws a hydropathy plot for a protein
 * sequence.
 * 
 * @param email - user email
 * @param title
 * @param window - Window size for hydropathy averaging.Default is 10.
 * @param normalize - Normalize data values. Default is false.
 * @param sequence - Protein sequence to analyse. The use of fasta formatted sequence is recommended.
 * @param result - address of file with resulting graph
 *
 * @author naviator.dev
 */
@SIBClass("ebi-sibs/Pepwindow")
@SIBStatus("IMPLEMENTED")
public class Pepwindow extends AbstractSIB {

	/* Branches */
	public static final String[] BRANCHES = { Branches.DEFAULT, Branches.ERROR };

	/* Parameters */
	public ContextExpression Email = new ContextExpression("${email}",
			String.class, false);
	public ContextExpression Title = new ContextExpression("", String.class,
			false);
	public ContextExpression Window = new ContextExpression("10", Integer.class,
			false);
	public ContextExpression Normalize = new ContextExpression("",
			Boolean.class, false);
	public ContextExpression Sequence = new ContextExpression("", String.class,
			false);
	public ContextKey result = new ContextKey("result", ContextKey.Scope.LOCAL,
			true);

	@Override
	public String execute(ExecutionEnvironment environment) {
		try {
			return ServiceAdapter.callPepwindow(environment, this.Email,
					this.Title, this.Window, this.Normalize, this.Sequence, this.result);
		} catch (NoClassDefFoundError e) {
			return Branches.ERROR;
		}
	}

	@Override
	public ServiceAdapterDescriptor generate() {
		return new ServiceAdapterDescriptor(LightweightServiceAdapter.class
				.getName(), "callPepwindow", "Email", "Title", "Window", "Normalize", "Sequence", "result");
	}

}
